package com.hdw.job.batch.job;

import com.hdw.common.base.BaseException;
import com.hdw.job.batch.processor.ChangeCursorResultProcessor;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.launch.support.RunIdIncrementer;
import org.springframework.batch.core.step.tasklet.TaskletStep;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class OdsToDwJob extends BaseJob {

    private String notNeedCheck;

    public OdsToDwJob() {
        super();
    }

    @Autowired
    ChangeCursorResultProcessor nullHandleProcessor;

    @Bean
    public Job odsToDwJobBean() throws BaseException {
        Map<String,Map<String,Object>> dimDataMap = new HashMap<>();
        TaskletStep beforeStep = super.buildBeforeStep();
        TaskletStep mainStep = this.buildMainStep(dimDataMap);
        Job job = jobBuilderFactory.get("odsToDwJobBean")
                .incrementer(new RunIdIncrementer())
                .start(beforeStep).next(mainStep)
                .build();
        return job;
    }

    protected TaskletStep buildMainStep(Map<String,Map<String,Object>> dimDataMap) throws BaseException {
        TaskletStep step = stepBuilderFactory.get("main_step")
                .<Map, Map>chunk(1024)
                .reader(selfJdbcCursorItemReader)
                .writer(noPkInsertWriter)
                .build();
        return step;
    }
}
